package com.lb.jwitter.action;

import java.util.Collection;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import com.lb.jwitter.util.ApplicationContextProvider;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Action;
import com.lb.jwitter.service.TblQuyenChiTietService;
import com.lb.jwitter.service.TblTaiKhoan;
import com.lb.jwitter.service.TblCTDTThayTheMonHoc;
import com.lb.jwitter.service.TblCTDTThayTheMonHocService;
import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

/**
 * @author QUOCVIET
 * 
 */

@ContextConfiguration(locations = "classpath:beans.xml")
public class TblCTDTThayTheMonHocAddFormAction {
	private int id;

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	private Collection<TblCTDTMonHoc> tblCTDTMonHocs;

	public Collection<TblCTDTMonHoc> getTblCTDTMonHocs() {
		return tblCTDTMonHocs;
	}

	private TblCTDTMonHocService tblCTDTMonHocService;

	private TblTaiKhoan taiKhoanDangNhap;

	public TblTaiKhoan getTaiKhoanDangNhap() {
		return taiKhoanDangNhap;
	}

	public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) {
		this.taiKhoanDangNhap = taiKhoanDangNhap;
	}

	private TblQuyenChiTietService tblQuyenChiTietService;
	@Autowired
	// Injected by Spring
	ApplicationContextProvider contextProvider;

	public String execute() throws Exception {
		try {
			Map session = ActionContext.getContext().getSession();
			taiKhoanDangNhap = (TblTaiKhoan) session.get("taiKhoan");
			if (taiKhoanDangNhap == null)
				return "noprivilege";
			ApplicationContext context = ApplicationContextProvider
					.getApplicationContext();
			tblQuyenChiTietService = (TblQuyenChiTietService) context
					.getBean("tbl_Quyen_ChiTietClient");
			if (!tblQuyenChiTietService
					.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(),
							"tbl_CTDT_ThayTheMonHoc", "them")) {
				return "noprivilege";
			}

			//tblCTDTMonHocService = (TblCTDTMonHocService) context.getBean("tbl_CTDT_MonHocClient");

			//tblCTDTMonHocs = tblCTDTMonHocService.findAlltblCTDTMonHoc(0, 0);

			return Action.SUCCESS;
		} catch (Exception e) {
			System.out.println("Loi AddForm tbl_CTDT_ThayTheMonHoc Action");
			e.printStackTrace();
			return Action.ERROR;
		}
	}
}
